//
//  KLBannerView.m
//  Koala
//
//  Created by cao pan on 11/23/14.
//  Copyright (c) 2014 Anonymous. All rights reserved.
//

#import "KLBannerView.h"

@implementation KLBanner

+ (NSArray *)testBannerArr
{
    NSMutableArray * bannerArr = [[NSMutableArray alloc] init];
    for (int i = 0 ; i < 6 ; i ++) {
        KLBanner * banner = [[KLBanner alloc] init];
        banner.imageNamed = [NSString stringWithFormat:@"cover_%d",i+1];
        banner.titleStr = @"布达拉宫的圣礼";
        banner.detailStr = @"在布达拉宫虔诚朝圣的路上...";
        [bannerArr addObject:banner];
    }
    return bannerArr;
}


@end



@interface KLBannerView()
{
    UILabel * _titleLabel;
    UILabel * _detailLabel;
    UIImageView * _imageView;

}

@end


@implementation KLBannerView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.7]];
        [self addImageView];
        [self addTitleLabel];
        [self addDetailLabel];
    }
    return self;
}


- (void)updateByBanner:(KLBanner *)banner
{
    [_titleLabel setText:banner.titleStr];
    [_detailLabel setText:banner.detailStr];
    [_imageView setImage:[UIImage imageNamed:banner.imageNamed]];
}


- (void)addTitleLabel
{
    _titleLabel = [[UILabel alloc] initWithFrame:self.bounds];
    [_titleLabel setHeight:20];
    [_titleLabel setOrigin:CGPointMake(10, self.bottom - 40)];
    [_titleLabel setFont:[UIFont boldSystemFontOfSize:17.0f]];
    [_titleLabel setTextColor:[UIColor whiteColor]];
    [self addSubview:_titleLabel];
    
}


- (void)addDetailLabel
{
     _detailLabel = [[UILabel alloc] initWithFrame:self.bounds];
    [_detailLabel setHeight:20];
    [_detailLabel setOrigin:CGPointMake(10, self.bottom - 20)];
    [_detailLabel setFont:[UIFont systemFontOfSize:13.0f]];
    [_detailLabel setTextColor:[UIColor whiteColor]];
    [self addSubview:_detailLabel];
    
}

- (void)addImageView
{
     _imageView = [[UIImageView alloc] initWithFrame:self.bounds];
    [_imageView setContentMode:UIViewContentModeScaleAspectFill];
    [_imageView setClipsToBounds:YES];
    [self sendSubviewToBack:_imageView];
    [self addSubview:_imageView];
}





@end
